{% extends 'common_tpl.html' %}
{% block content2 %}
    <div class="container" style="margin-top: 20px;">
        <table class="table">
            <thead>
            <tr>
                <th>权限名称</th>
                <th>数量</th>
                <th>单价</th>
                <th>总价</th>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td>{{ right_obj.title }}</td>
                <td>{{ quantity }}</td>
                <td>{{ right_obj.price }}</td>
                <td>{{ total_price }}</td>
            </tr>
            </tbody>
        </table>
        <hr/>
        <div>
            <div class="text-danger">请确认要购买的订单信息</div>
            <div class="h3">支付金额：￥{{ total_price }}</div>
            <button id="pay" class="btn btn-success" price="{{ total_price }}">确认支付</button>
        </div>
    </div>
    {% csrf_token %}
{% endblock %}
{% block js %}
    <script>
        $(function () {
            bindPay();
        })

        function bindPay() {
            $("#pay").click(function () {
                $.ajax({
                    url: "{% url 'main:api_payment' %}",
                    headers: {
                        'X-CSRFTOKEN': $("[name='csrfmiddlewaretoken']").val(),
                    },
                    data: {
                        order_by_user:{{ request.user.id }},
                        order_right:{{ right }},
                        order_price:{{ total_price }},
                        order_quantity: {{ quantity }}
                    },
                    dataType: 'json',
                    type: 'post',
                    success: function (res) {
                        console.log(res)
                        if (res.ret === 0) {
                            location.href = res.payurl
                        }
                    }

                })
            })
        }
    </script>
{% endblock %}
